#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    string reverseMessage(string message) {
        if (message.size() == 0)
            return "";

        vector<string> rever(0);
        int n = message.size();

        for (int i = 0; i < n; ++i)
        {
            if (message[i] != ' ')
            {
                for (int j = i; j < n; ++j)
                {
                    if (message[j] == ' ')
                    {
                        rever.push_back(string(message.begin() + i, message.begin() + j));
                        i = j;
                        break;
                    }
                    if (j == n - 1)
                    {
                        rever.push_back(string(message.begin() + i, message.begin() + j + 1));
                        i = j + 1;
                        break;
                    }
                }
            }
        }

        string ret;
        for (int i = rever.size() - 1; i >= 0; --i)    ret += rever[i] + ' ';

        if (ret.size() > 0)
            ret.resize(ret.size() - 1);

        return ret;
    }
};